﻿using System.Collections;
using Model;
using NHibernate;
using NHibernate.Expression;


namespace DataAccess
{
    public class PreventiveDataAccess : BaseDataAccess
    {

        
        public Preventive GetPreventiveById(int preventiveId)
        {
            Preventive item = new Preventive();
            ICriteria crit = m_session.CreateCriteria(typeof(Preventive));
            crit.Add(Expression.Eq(Preventive.CONST_PREVENTIVE_ID, preventiveId));
            if (crit.List().Count != 0) item = crit.List()[0] as Preventive;
            return item;
        }
        public IList GetMaintenanceCategoryByTypeId(int typeId)
        {
           
            ICriteria crit = m_session.CreateCriteria(typeof(MaintenanceCategory));
            crit.Add(Expression.Eq(MaintenanceCategory.CONST_EQUIPMENT_TYPE_ID, typeId));
            
            return crit.List();

       }
        public MaintenanceCategory IsAlreadyExistMaintenanceCategory(int typeId,string description)
        {
            MaintenanceCategory model = new MaintenanceCategory();
            ICriteria crit = m_session.CreateCriteria(typeof(MaintenanceCategory));
            crit.Add(Expression.Eq(MaintenanceCategory.CONST_EQUIPMENT_TYPE_ID, typeId));
            crit.Add(Expression.Like(MaintenanceCategory.CONST_DESC, description));
            if (crit.List().Count != 0) model = crit.List()[0] as MaintenanceCategory;
            return model;
        }
        
    }
}
